
package org.apache.dubbo.remoting;

import org.apache.dubbo.rpc.model.ScopeModel;
import org.apache.dubbo.rpc.model.ScopeModelUtil;

public class Transporter$Adaptive implements Transporter {
    public Client connect(org.apache.dubbo.common.URL url, ChannelHandler handler)
            throws RemotingException {

        String extName = url.getParameter("client",
                url.getParameter("transporter", "netty"));
        if (extName == null)
            throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.Transporter) name from url (" + url.toString() + ") use keys([client, transporter])");

        ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), Transporter.class);

        Transporter extension = (Transporter)
                scopeModel.getExtensionLoader(Transporter.class).getExtension(extName);

        return extension.connect(url, handler);
    }

    public RemotingServer bind(org.apache.dubbo.common.URL url, ChannelHandler handler)
            throws RemotingException {

        String extName = url.getParameter("server", url.getParameter("transporter", "netty"));
        if (extName == null)
            throw new IllegalStateException("Failed to get extension (org.apache.dubbo.remoting.Transporter) name from url (" + url.toString() + ") use keys([server, transporter])");

        ScopeModel scopeModel = ScopeModelUtil.getOrDefault(url.getScopeModel(), Transporter.class);

        Transporter extension = (Transporter)
                scopeModel.getExtensionLoader(Transporter.class).getExtension(extName);

        return extension.bind(url, handler);
    }
}
